from django.db import models


class User(models.Model):
    userName = models.CharField(max_length=20, null=False, verbose_name="用户名")
    password = models.CharField(max_length=20, null=False, verbose_name="用户密码")
    gender = models.IntegerField(null=True, verbose_name="性别")  # 0代表男 1代表女
    birthday = models.DateTimeField(null=True, verbose_name="出生日期")
    phone = models.CharField(max_length=20, null=True, verbose_name="电话")
    email = models.CharField(max_length=32, null=True, verbose_name="电子邮件")
    address = models.CharField(max_length=64, null=True, verbose_name="地址")
    type = models.IntegerField(null=True, default=0, verbose_name="类型")
    status = models.IntegerField(null=True, default=0, verbose_name="状态")
    depart = models.CharField(max_length=32, null=True, verbose_name="部门")
    company = models.CharField(max_length=32, null=True, verbose_name="单位")
    createTime = models.DateTimeField(null=True, verbose_name="添加时间")
    remark = models.CharField(max_length=512, null=True, verbose_name="备注")

    class Meta:
        db_table = "tb_user"


class SpiderTask(models.Model):
    """
    采集任务模型类
    """
    taskName = models.CharField(max_length=32, null=False, verbose_name="任务名称")
    taskUrl = models.CharField(max_length=128, null=False, verbose_name="任务URL")
    createTime = models.DateTimeField(null=True, verbose_name="发布时间")
    createBy = models.IntegerField(null=True, verbose_name="发布人")
    startTime = models.DateTimeField(null=True, verbose_name="开始时间")
    endTime = models.DateTimeField(null=True, verbose_name="结束时间")
    executeTime = models.DateTimeField(null=True, verbose_name="执行时间")
    executeBy = models.IntegerField(null=True, verbose_name="执行人")
    status = models.IntegerField(null=True, verbose_name="任务状态")  # 0未执行，1执行中，2已完成
    type = models.IntegerField(null=True, verbose_name="任务类型")
    remark = models.CharField(max_length=512, null=True, verbose_name="备注")

    class Meta:
        db_table = "tb_spider"


class Analysis(models.Model):
    """
    数据分析模型类--> tb_analysis
    """
    fileName = models.CharField(max_length=32, null=False, verbose_name="文件名")
    fileUrl = models.FileField(upload_to="upload", null=True, verbose_name="文件路径")
    fileSize = models.IntegerField(null=True, verbose_name="文件大小")
    fileType = models.IntegerField(null=True, verbose_name="文件类型")
    fileStatus = models.IntegerField(null=True, verbose_name="文件状态")
    uploadTime = models.DateTimeField(null=True, verbose_name="上传时间")
    uploadBy = models.IntegerField(null=True, verbose_name="上传人")
    executeTime = models.DateTimeField(null=True, verbose_name="处理时间")
    executeBy = models.IntegerField(null=True, verbose_name="处理人")
    remark = models.CharField(max_length=512, null=True, verbose_name="备注")

    class Meta:
        db_table = "tb_analysis"


class Member(models.Model):
    """
    会员模型类--> 会员信息表 --> tb_member
    """
    account = models.CharField(max_length=20, null=False, verbose_name="会员账号")
    password = models.CharField(max_length=20, null=False, verbose_name="会员密码")
    headUrl = models.FileField(upload_to="head", null=True, verbose_name="会员头像")
    gender = models.IntegerField(null=True, default="0", verbose_name="性别")
    birthday = models.DateTimeField(null=True, verbose_name="出生日期")
    realName = models.CharField(max_length=20, null=True, verbose_name="真实姓名")
    phone = models.CharField(max_length=20, null=True, verbose_name="手机号码")
    email = models.CharField(max_length=20, null=True, verbose_name="电子邮件")
    province = models.CharField(max_length=20, null=True, verbose_name="省份")
    city = models.CharField(max_length=20, null=True, verbose_name="城市")
    address = models.CharField(max_length=32, null=True, verbose_name="地址")
    type = models.IntegerField(null=True, default=0, verbose_name="会员类型")
    status = models.IntegerField(null=True, default=0, verbose_name="会员状态")
    shopId = models.IntegerField(null=True, verbose_name="所属店铺")
    points = models.IntegerField(null=True, default=0, verbose_name="会员积分")
    balance = models.FloatField(null=True, default=0.0, verbose_name="会员余额")
    registerTime = models.DateTimeField(null=True, verbose_name="注册时间")
    registerBy = models.IntegerField(null=True, verbose_name="注册人")
    updateTime = models.DateTimeField(null=True, verbose_name="更新时间")
    updateBy = models.IntegerField(null=True, verbose_name="更新人")
    remark = models.CharField(max_length=512, null=True, verbose_name="备注")

    class Meta:
        db_table = 'tb_member'


class Shop(models.Model):
    """
    所属门店
    """
    shopName = models.CharField(max_length=32, null=False, verbose_name="门店名称")
    province = models.CharField(max_length=20, null=True, verbose_name="省份")
    city = models.CharField(max_length=20, null=True, verbose_name="城市")
    address = models.CharField(max_length=512, null=True, verbose_name="地址")

    class Meta:
        db_table = "tb_shop"


class Order(models.Model):
    """
    订单模型类：--> 订单表 --> tb_order
    会员编号：--> 会员对象--> 会员名称
    """
    member = models.ForeignKey(Member, related_name="order", on_delete=models.CASCADE)
    buyTime = models.DateTimeField(null=True, verbose_name="购买时间")
    payType = models.IntegerField(default=0, null=True, verbose_name="支付方式")  # 银联 支付 微信
    payMoney = models.FloatField(null=True, verbose_name="支付金额")
    buyShop = models.ForeignKey(Shop, null=True, on_delete=models.CASCADE, verbose_name="所属门店")
    type = models.IntegerField(null=True, default=0, verbose_name="订单类型")
    status = models.IntegerField(default=0, null=True, verbose_name="订单状态")
    updateTime = models.DateTimeField(null=True, verbose_name="更新时间")
    updateBy = models.IntegerField(null=True, verbose_name="更新人")
    remark = models.CharField(max_length=512, null=True, verbose_name="备注")

    class Meta:
        db_table = "tb_order"


class OrderDetail(models.Model):
    """
    订单明细模型：--> 订单明细表 --> tb_orderDetail
    """
    order = models.ForeignKey(Order, related_name="order", on_delete=models.CASCADE, verbose_name="订单外键")
    productName = models.CharField(max_length=32, null=False, verbose_name="商品名称")
    salePrice = models.FloatField(null=True, verbose_name="商品售价")
    discountPrice = models.FloatField(null=True, verbose_name="折扣价")
    numbers = models.IntegerField(null=True, default=0, verbose_name="数量")
    industry = models.IntegerField(null=True, default=0, verbose_name="行业")
    shop = models.ForeignKey(Shop, on_delete=models.CASCADE, verbose_name="所属门店")
    variant = models.CharField(max_length=32, null=True, verbose_name="商品规格")
    totalMoney = models.FloatField(null=True, verbose_name="总价")
    remark = models.CharField(max_length=512, null=True, verbose_name="备注")

    class Meta:
        db_table = "tb_orderDetail"
